package com.etc.layuisys.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.etc.layuisys.dao.UsersDao;
import com.etc.layuisys.entity.Users;
import com.etc.layuisys.service.UsersService;
import com.etc.layuisys.utils.MD5Util;
import com.etc.layuisys.utils.PageData;

@Service(value = "usersService")
public class UsersServiceImpl implements UsersService {

	@Resource(name = "usersDao")
	private UsersDao ud;

	@Override
	public PageData<Users> getUsersByPage(int page, int pageSize, String content) {
		// TODO Auto-generated method stub

		return ud.getUsersByPage(page, pageSize, content);
	}

	@Override
	public boolean addUsers(Users user) {
		// TODO Auto-generated method stub
		if (user == null) {
			return false;
		} else {
			user.setUserPwd(MD5Util.getEncodeByMd5(user.getUserPwd()));
			// 测试
			System.out.println("service:" + user);

			return ud.addUsers(user);
		}

	}

	@Override
	public Users login(Users user) {
		// TODO Auto-generated method stub
		if (user == null) {
			return null;
		} else {
			user.setUserPwd(MD5Util.getEncodeByMd5(user.getUserPwd()));
			return ud.getUser(user);
		}
	}

	@Override
	public boolean userNameValidate(String userName) {
		// TODO Auto-generated method stub
		if (userName == null) {
			return false;
		} else {
			return ud.getUsers(userName);
		}
	}

	@Override
	public boolean DeleteUser(int userId) {
		// TODO Auto-generated method stub
		return ud.DeleteUser(userId);
	}

	@Override
	public boolean updateUser(Users user) {
		// TODO Auto-generated method stub
		return ud.updateUser(user);
	}

}
